#include "LCD_utils.h"
#include "LCD_ILI9325.h"




/********************************************************************************/
/*
*       IMPLEMENTATION DE LA PROGRESS BAR EN POURCENTAGE
*/
/********************************************************************************/

_progressBar newProgessBar()
{   
    _progressBar progressBar = {start, grow};

    return progressBar;
}
/*
void grow(uint8_t pourcent)
{
    if ( pourcent > 100 )
        pourcent = 100;
    
    xQueueSendToBack( progressBarQueue, &pourcent, 0);
}*/


void start(uint16_t startX,uint16_t startY, uint16_t width,uint16_t height,uint16_t color)
{
    uint16_t tab[5] = { startX, startY, width, height, color};

    xTaskCreate( (void*)vTaskProgressBar, (void*)"progressBar", configMINIMAL_STACK_SIZE+128, tab, tskIDLE_PRIORITY+4, NULL );
}
/*
void vTaskProgressBar(uint16_t tab[5])
{
    uint32_t i,j;
    portTickType xLastWakeTime;
    xLastWakeTime = xTaskGetTickCount();
    uint32_t hei = tab[1], wei = 320-tab[0];
    uint8_t pourcent = 0, value = 0;

    while( pourcent < 100 )
    {
        if ( uxQueueMessagesWaiting( progressBarQueue ) != 0 )
        {
            xQueueReceive( progressBarQueue, &value, 10); 
            pourcent += value;

            ILI9325_SetCursorPos(tab[1], 320-tab[0]);

            ILI9325_SetRegister(0x0003, 0x1010);

            for(j = 0; j < ((tab[2]*pourcent)/100); j++)
            {
                for(i = 0; i < tab[3]; i++)
                {
                    ILI9325_SetRegister(0x0022, tab[4]);  
                }
                if ( (wei-1) != 0 )
                    ILI9325_SetCursorPos(hei , wei--);
              }
        }
        else
            vTaskDelayUntil( &xLastWakeTime, 100/portTICK_RATE_MS);
    }

    vTaskDelete(NULL);
}*/
/********************************************************************************/
/********************************************************************************/